//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
//
// (C) Copyright 2006 Marvell International Ltd.
// All Rights Reserved
//
#include <windows.h>
#include <oal.h>

#include "monahans_base_regs.h"
#include "xllp_defs.h"
#include "xllp_pm_Micco.h"
#include "xllp_i2c.h"

void EnableSRAMPowerDomain(void)
{
	// LD0 Vars
	XLLP_VUINT32_T * pOST, * pI2C, *pMFP;
	XLLP_UINT8_T buf[2];
	XLLP_STATUS_T ret = 0;
	char pMfpRMDb[XLLP_MFP_RM_DB_SIZE];

	//RETAILMSG(TRUE, (L"Enable Internal SRAM Power Domain\r\n"));

	// Enable LD0
	//
	pOST= (XLLP_VUINT32_T *) OALPAtoVA(MONAHANS_BASE_REG_PA_OST, FALSE);
	pI2C= (XLLP_VUINT32_T *) OALPAtoVA(MONAHANS_BASE_REG_PA_I2C, FALSE);
	pMFP= (XLLP_VUINT32_T *) OALPAtoVA(MONAHANS_BASE_REG_PA_MFP, FALSE);

	if (XLLP_STATUS_SUCCESS!=XllpMfpResourceManagerInit(pMfpRMDb))
	{
		RETAILMSG(TRUE, (L"XllpMfpResourceManagerInit() failed!\r\n"));
	}

	XllpI2cInit((P_XLLP_I2C_T)pI2C, (P_XLLP_VUINT32_T) pMFP, (P_XLLP_MFP_RM_DB_ID_T )pMfpRMDb, 0);
/* TODO  */
	XllpPmMiccoRead ((P_XLLP_I2C_T) pI2C, (XLLP_OST_T *)pOST, 0x17, buf);

	buf[0] |= 0x20; // 0xFF;
/* TODO  */
	XllpPmMiccoWrite ((P_XLLP_I2C_T) pI2C, (XLLP_OST_T *)pOST, 0x17, buf[0]);
}


void DisableSRAMPowerDomain(void)
{
    /* It always can not turn off the SRAM LDO of PMIC */
    /* The reason is that BOOTROM never know the PMIC LDO status and it need to use SRAM during reset */
#if 0
	// LD0 vars
	XLLP_VUINT32_T * pOST, * pI2C, *pMFP;
	XLLP_UINT8_T buf[2];
	XLLP_STATUS_T ret = 0;
	char pMfpRMDb[XLLP_MFP_RM_DB_SIZE];

	//RETAILMSG(TRUE, (L"Disable Internal SRAM Power Domain\r\n"));

	// Disable LD0
	//
	pOST= (XLLP_VUINT32_T *) OALPAtoVA(MONAHANS_BASE_REG_PA_OST, FALSE);
	pI2C= (XLLP_VUINT32_T *) OALPAtoVA(MONAHANS_BASE_REG_PA_I2C, FALSE);
	pMFP= (XLLP_VUINT32_T *) OALPAtoVA(MONAHANS_BASE_REG_PA_MFP, FALSE);

	if (XLLP_STATUS_SUCCESS!=XllpMfpResourceManagerInit(pMfpRMDb))
	{
		RETAILMSG(TRUE, (L"XllpMfpResourceManagerInit() failed!\r\n"));
	}

	XllpI2cInit((P_XLLP_I2C_T)pI2C, (P_XLLP_VUINT32_T) pMFP, (P_XLLP_MFP_RM_DB_ID_T )pMfpRMDb, 0);

	XllpPmMiccoRead ((P_XLLP_I2C_T) pI2C, (XLLP_OST_T *)pOST, 0x17, buf);

	buf[0] &= 0xDF; // Turn off LD015
             ret=XllpPmMiccoWrite ((P_XLLP_I2C_T) pI2C, (XLLP_OST_T *)pOST, 0x17, buf[0]);
#endif

}

